package cn.yitun.chat.yitunserverimcore.general.main.push.group;

import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.group.GroupInvitePushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import cn.yitun.chat.yitunserverimcore.general.common.util.PushMessageBuild;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 群邀请信息相关
 * Date 2019-01-27 21:43:21<br>
 * Description
 * 
 * @author yitun<br>
 * @version 1.1
 */
@Service
public class GroupInvitePush {
	//1.2.207
	final String action = ActionTypeConstant.GROUP_INVITE_ACTION_PUSH;

	@Resource
	WriteHandler writeHandler;

	/**
	 * 邀请申请
	 * @param key
	 * @param groupId
	 * @param applyId
	 * @param userIds
	 */
	public void pushInviteApply(Long key, Long groupId, Long applyId, List<Long> userIds) {
		String method = GroupInvitePushMethodEnum.INVITE_APPLY.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("groupId", groupId);
		message.bodyPut("applyId", applyId);
		writeHandler.push(YitunStringUtil.toStrList(userIds), message);
	}

	/**
	 * 邀请
	 * @param key
	 * @param groupId
	 * @param applyId
	 * @param userId
	 */
	public void pushInvite(Long key, Long groupId, Long applyId, Long userId) {
		String method = GroupInvitePushMethodEnum.INVITE.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("groupId", groupId);
		message.bodyPut("applyId", applyId);
		writeHandler.push(userId, message);
	}
}
